import axios from 'axios';
const debug = process.env.NODE_ENV !== 'production';

let baseURL = debug ? 'api' : 'http://coderyl.top/wyymusic';

const service = axios.create({
  baseURL,
  withCredentials: true,
  timeout: 1000 * 12,
});

// 请求 拦截器
service.interceptors.request.use(
  (config) => {
    // console.log('config', config);
    return config;
  },
  (error) => Promise.error(error)
);

// 响应 拦截器
service.interceptors.response.use(
  (response) => {
    const res = response.data;
    return res;
  },
  (error) => {
    const errMsg = `error: ${error}`;
    console.log(errMsg);
    return Promise.reject(error);
  }
);

export default service;
